/*
Pew ATP W67 for human activity q. */
clear
* Update the path below to your local copy of the Pew ATP Wave 67 data (.dta format)
* Available from: https://www.pewresearch.org/dataset/american-trends-panel-wave-67/
use "ATP W67.dta"
set more off

/* Prelim vars of interest:

Partisanship
College educ
Sex
Age */

// Party ID
gen partyid3=.
replace partyid3=1 if F_PARTYSUM_FINAL==2
replace partyid3=2 if F_PARTYSUM_FINAL==1
replace partyid3=3 if F_PARTYSUM_FINAL==9
label define partyid3 1 "Democratic" 2 "Republican" 3 "Independent", replace
label values partyid3 partyid3

gen pid3=.
replace pid3=1 if partyid3==1
replace pid3=2 if partyid3==3
replace pid3=3 if partyid3==2
label define pid3 1 "Dem" 2 "Ind/DK" 3 "Rep", replace
label values pid3 pid3

// Sex
gen male=.
replace male=1 if F_SEX==1
replace male=0 if F_SEX==2
label define male 0 "Female" 1 "Male" 
label values male male

// college degree
gen collegedeg=.
replace collegedeg=0 if F_EDUCCAT>1 & !missing(F_EDUCCAT)
replace collegedeg=1 if F_EDUCCAT==1

** age
gen agedem=.
label define agedem 1 "18-29" 2 "30-49" 3 "50-65" 4 "65+"
replace agedem=1 if F_AGECAT==1
replace agedem=2 if F_AGECAT==2
replace agedem=3 if F_AGECAT==3
replace agedem=4 if F_AGECAT==4

** human activity
tab EN7
gen human=.
replace human=1 if EN7==1
replace human=0 if EN7==2 | EN7==3 | EN7==4

/////////////////////////////////////
// weight: WEIGHT_W67

* cd to output directory (update as needed)

set scheme plottig
reg human b2.pid3 male i.agedem college [pweight=WEIGHT_W67] 
eststo All
margins, at(pid=(1,2,3)) 
mplotoffset, recast(scatter) offset(0.15) title("Pew ATP W67: Agreement that human activity contributes a great deal to climate change") ///
xtitle("Partisanship") ytitle("Predicted probabilities") legend(ring(1) pos(6) row(1)) 


set scheme plottig
logit human b2.pid3 male i.agedem college [pweight=WEIGHT_W67] 
eststo All
margins, at(pid=(1,2,3)) 
mplotoffset, recast(scatter) offset(0.15) title("Human activity main contributor to climate change") ///
ylabel(0 "0" .10 "10%" .20 "20%" .30 "30%" .40 "40%" .50 "50%" .60 "60%" .70 "70%" .80 "80%" .90 "90%" 1 "100%") ///
xtitle("Partisanship") ytitle("") legend(ring(1) pos(6) row(1)) 
graph save Pew, replace


/////

// means

mean human [pweight=WEIGHT_W67]
mean human [pweight=WEIGHT_W67], over(pid3)